/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 3

Using:	hw_code\Hw3Types.h
		hw_code\IspImage.h
		hw_code\Bmp24LineReader.h		

Description:
The Manager is the program. It manages everything, and controls the flow 
of the program.
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#ifndef MANAGER_H
#define MANAGER_H

#include "hw_code\Hw3Types.h"
#include "hw_code\IspImage.h"
#include "hw_code\Bmp24LineReader.h"


// A Gloabl struct that holds the parameters of the picture, and the picture itself
typedef struct 
{
	// The picture
	IspImage Picture;
	// Height and Width
	int PictureHeight;
	int PictureWidth;
	// The current line available of the picture (The last line that was read)
	int lastReadLine;
	HANDLE lastReadLineProtector;
} TPicture;

// A Gloabl struct that holds parameters
typedef struct
{
	int FaceWidth;
	int FaceHeight;
	int MaxDiffPixelsBetweenFaces;
} TParameters;

extern TPicture GlobalPicture;
extern TParameters GlobalParameters;

//////////////////////////////////////////////////////////////////////////
// Manager Functions
//////////////////////////////////////////////////////////////////////////
/* ManagerInitialize(
 *	char* bitmapFilename, 
 *	char* outputFilename, 
 *	int faceWidth, 
 *	int faceHeight, 
 *	int verticalAreasCount, 
 *	int horizontalAreasCount, 
 *	int parallelThreads);
 * -----------------------------------
 * Initializes the program with all the necessary parameters.
 * Parameters are self-explanotary and defined in the excersize requirements			*/
BOOL ManagerInitialize(char* bitmapFilename, char* outputFilename, int faceWidth, int faceHeight, int verticalAreasCount, int horizontalAreasCount, int parallelThreads);

/* ManagerFree()
 * -----------------------------------
 * Initializes the program with all the necessary parameters.
 * Parameters are self-explanotary and defined in the excersize requirements			*/
void ManagerFree();

BOOL ManagerRun();

//////////////////////////////////////////////////////////////////////////
// Thread Synchronization Functions
//////////////////////////////////////////////////////////////////////////

// GetRunPermission() - Waits for permissions to run
void WaitForRunPermission();
// ReleaseRunPermission() - Releases the permissions given by WaitForRunPermission
void ReleaseRunPermission();

// NotifyLineRead() - Notifies all threads that are waiting for the next line
void NotifyLineRead();

// NotifyReadingFinished() - Notifies all threads that there is no more need to wait on the LineRead event
void NotifyReadingFinished();

// WaitLineRead - Waits until the a line is read
BOOL WaitLineRead(const int lineNumber);

// Check if program has terminated
BOOL ProgramTerminated();

// Wait until program has terminated
BOOL WaitForProgramTerminate(int timeout);

// NotifyTerminateProgram() - Notifies all threads that program has been terminating
void TerminateProgram();


#endif // MANAGER_H